<template>
  <div>
    <el-container style="height: 500px; border: 1px solid #eee">
      <el-aside width="200px" style="background-color: rgb(238, 241, 246)">
        <el-menu router="true">
          <el-menu-item>
            <i class="el-icon-menu"></i>
            <span slot="title">导航</span>
          </el-menu-item>
          <el-menu-item index="/homePage">首页</el-menu-item>
          <el-menu-item index="/AccountTable">用户信息表</el-menu-item>
          <el-menu-item index="/yqdkTable">打卡信息表</el-menu-item>
        </el-menu>
      </el-aside>

      <el-container>
        <el-header style="text-align: right; font-size: 12px">
          <el-dropdown @command="handleCommand">
            <el-avatar src="https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png"></el-avatar>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item command="out">退出</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>

        </el-header>

        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>

</template>

<script>
  export default {
    created() {
      this.initPage();
    },
    methods: {
      initPage(){
        this.$axios.get('/admin').then((response)=>{
            this.$router.replace({path: '/homePage'});
        }).catch(()=>{
          this.$router.replace({path: '/'});
          location.reload();
        });
      },
      handleCommand(command) {
        if (command == "out"){
          this.$axios.get('/logout').then().catch(()=>{
            sessionStorage.clear();
            this.$router.replace({path: '/'});
            location.reload();
          });
        }
      }
    }
  }
</script>

<style>
  .el-header {
    background-color: #42b983;
    color: #333;
    line-height: 60px;
  }

  .el-aside {
    color: #333;
  }
</style>
